package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:JKD17新增语法
 * User: LianBao
 * Date: 2024-03-19
 * Time: 14:15
 */


//密封类

sealed class Animal permits Dog {

}

non-sealed class Dog extends Animal {

}

public class Test2 {


    //2.var:自动推导类型
    //但是var不能声明字段(成员属性)/方法参数/方法返回值
    //var声明的必须初始化,不能初始化为null
    public static void main2(String[] args) {
        var age = 10;
        var name = "hello";
    }

    //1.case语句
    public static void main1(String[] args) {
        String data = "one";
        int result = switch (data) {
            case "one" -> 1;
            case "two" -> 2;
            default -> -1;
        };
        int result2 = switch (data) {
            case "one":
                yield 1;
            case "two":
                yield 2;
            default:
                yield -1;
        };
    }
}
